package com.wbp.cms.core.profileutil;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JProfilerUtil {

	protected static final Logger LOGGER = LoggerFactory.getLogger(JProfilerUtil.class);

	private static final Long defaultTime = 3000L ;
	
    public JProfilerUtil() {
    }

    public static void start(String message) {
        JProfiler.start(message);
    }

    public static void reset() {
    	JProfiler.release();
        long duration = JProfiler.getDuration();
        if(duration > (long)Math.max(500, defaultTime)) {
            LOGGER.warn("Order request returned in {}ms\n{}\n", Long.valueOf(duration), getDetail());
        }

        JProfiler.reset();
    }

    private static String getDetail() {
        return JProfiler.dump("Detail: ", "        ");
    }
}
